<script setup lang="ts">
import WebExcel from "./../../../src/index"
import useTable from "./useTable";
const { columns, dataSource } = useTable()

function contextmenu({ columns, records, rowindexs }){
    return [
        {
            label: "向下插入行",
            onClick: () => {
                dataSource.value.splice(rowindexs.at(-1) + 1, 0, {})
            }
        },
        {
            label: "向上插入行",
            onClick: () => {
                dataSource.value.splice(rowindexs.at(-1) + 1, 0, {})
            },
            disabled: rowindexs[0] === 0
        }
    ]
}
</script>

<template>
    <h4>自定义右键菜单</h4>
    <WebExcel 
        :columns="columns" 
        :dataSource="dataSource" 
        :contextmenu="contextmenu" 
        :visibleContextmenu="true"
    >
    </WebExcel>
</template>